package com.example.dbmysql.service.impl;


import com.example.dbmysql.mapper.RoomTypeMapper;
import com.example.dbmysql.pojo.RoomType;
import com.example.dbmysql.service.RoomTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class RoomTypeServiceImpl implements RoomTypeService {
    @Autowired
    private RoomTypeMapper roomTypeMapper;

    @Override
    public  void  add(RoomType roomType){
        roomTypeMapper.add(roomType);
    }

    @Override
    public RoomType findByTypeName(String typeName) {
        return   roomTypeMapper.findByTypeName(typeName);

    }

    @Override
    public PageInfo<RoomType> selectAll(int page, int pageSize) {


        PageHelper.startPage(page, pageSize);
        // 查询全部数据
        List<RoomType> AllRoomList = roomTypeMapper.selectAll(page, pageSize);

        PageInfo<RoomType> pageInfo = new PageInfo<>(AllRoomList);

        return pageInfo;
    }

    @Override
    public RoomType updateById(RoomType roomType) {
        roomType.setUpdateTimer(LocalDateTime.now());
        roomTypeMapper.PutUpdateById(roomType);
        return roomType;
    }

    @Override
    public RoomType geRoomTypeById(Integer id) {
        return roomTypeMapper.geRoomTypeById(id);
    }

    @Override
    public void delRoomTypeById(Integer id) {
         roomTypeMapper.delRoomTypeByid(id);
    }


}
